var _pInfo = {
	"shareUrl": null,
	"qrcode": null,
	"qrcodeUrl": null,
	"userInfo": null,
	"param": getQueryParams(),
	"shareToFriend": function() {
<<<<<<< HEAD
		WalletInteractive.shareUrlTitle(this.shareUrl, "");
=======
		shareUrlTitle(this.shareUrl, "");
>>>>>>> c7b8bb0815e40561f3df48818c02bb58d1b1c469
	},
	"saveQrcode": function() {
		$.toast("请长按二维码保存", "text");
		//this.download();
		//window.open(this.qrcodeUrl);
	},
	"download": function() {
		let imgData = this.qrcodeUrl;
		this.downloadFile('share_qrcode.png', imgData);
	},
	//下载
	"downloadFile": function(fileName, content) {
		let aLink = document.createElement('a');
		let blob = this.base64ToBlob(content); //new Blob([content]);
		let evt = document.createEvent("HTMLEvents");
		evt.initEvent("click", true, true); //initEvent 不加后两个参数在FF下会报错  事件类型，是否冒泡，是否阻止浏览器的默认行为
		aLink.download = fileName;
		aLink.href = URL.createObjectURL(blob);
		// aLink.dispatchEvent(evt);
		aLink.click();
		//$.toast("保存成功", "text");
	},
	//base64转blob
	"base64ToBlob": function(code) {
		let parts = code.split(';base64,');
		let contentType = parts[0].split(':')[1];
		let raw = window.atob(parts[1]);
		let rawLength = raw.length;
		let uInt8Array = new Uint8Array(rawLength);
		for(let i = 0; i < rawLength; ++i) {
			uInt8Array[i] = raw.charCodeAt(i);
		}
		return new Blob([uInt8Array], {
			type: contentType
		});
	},
	"renderData": function() {
		AjaxRequest({
			url: _url + "/money/wallet/walleturl",
			type: "post",
			load: true,
			async: false,
			data: {
				"walletUrl": _pInfo.shareUrl
			},
			success: function(rs) {
				if(isReqSucceed(rs)) {
					_pInfo.qrcodeUrl = _url + rs.data;
					$("#personal-content").html(template("personal-content-tpl", {
						rs: rs.data,
						url: _url
					}));
				}
			}
		});
	},
	"loadEvents": function() {
		_pInfo.userInfo = _user.getUserInfo();
		var _referee = "";
		var _pageUrl = "";
		if(_pInfo.userInfo.email != "") {
			_pageUrl = "/money/login/emailRegister/emailRegister.html?referee=";
			_referee = _pInfo.userInfo.email;
		}
		if(_pInfo.userInfo.tel != "") {
			_pageUrl = "/money/login/phoneRegister/phoneRegister.html?referee=";
			_referee = _pInfo.userInfo.tel;
		}
		this.shareUrl = _url + _pageUrl + _referee;
		this.renderData();
		//		_pInfo.qrcode = new QRCode(document.getElementById("qrcode"));
		//		_pInfo.qrcode.makeCode(this.shareUrl);
		//		$("#download").attr("href", $("#qrcode img").attr("src"));
	},
	"load": function() {
		this.loadEvents();
	}
}
exposeGlobalMethods({
	"shareToFriend": function() {
		_pInfo.shareToFriend();
	},
	"saveQrcode": function() {
		_pInfo.saveQrcode();
	}
});
$(function() {
	_pInfo.load();
});